package com.android.gl2jni.filter;

import android.content.Context;
import com.android.gl2jni.ShaderUtils;

/**
 * Create time: 2018/9/15.
 */
public class ASCIIFilterProgram extends TextureFilterProgram {
  private int miResolutionLoc;
  private int zoomLoc;
  private float zoom = 2f;

  /**
   * Prepares the program in the current EGL context.
   */
  public ASCIIFilterProgram(Context context) {
    super(context, ProgramType.TEXTURE_EXT);
  }

  @Override
  protected String getFragmentShaderSourceEXT() {
    return ShaderUtils.readAssetsTextFile(getContext(),
        "filter/fsh/shadertoy/ascii_art.glsl");
  }

  @Override
  protected void initProgram() {
    super.initProgram();
    miResolutionLoc = getUniformLocation("iResolution");
    zoomLoc = getUniformLocation("zoom");
  }

  @Override
  protected void onDraw(int firstVertex, int vertexCount) {
    setFloatVec2(miResolutionLoc, new float[]{(float) surfaceWidth, (float) surfaceHeight});
    setFloat(zoomLoc, zoom);
    super.onDraw(firstVertex, vertexCount);
  }

  public void setZoom(float zoom) {
    this.zoom = zoom;
  }
}
